home *** CD-ROM | disk | FTP | other *** search
/ 5 Star Games: DOS Edition 2 / 5 Star Games - DOS Edition (1995)(Ready to Run).iso / dbc / extfhc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-28  |  2.3 KB  |  91 lines

  1. /****************************************************************************/
  2. /*                         DATABOSS MODULE: EXTFHC.C                        */
  3. /****************************************************************************/
  4.  
  5. #include "db_lsc.h"
  6.  
  7. #ifdef __TURBOC__
  8.     #include <mem.h>
  9. #else
  10.     #include <graph.h>
  11.     #include <string.h>
  12. #endif
  13. #include <dos.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <conio.h>
  17. #include "db_types.h"
  18. #include "db_conio.h"
  19. #include "db_dmem.h"
  20. #include "db_dos.h"
  21. #include "extfhc.h"
  22.  
  23. /*****************************  INTERNAL TYPES  *****************************/
  24.  
  25. typedef byte         handlearray[255];
  26. typedef handlearray *handlearrayptr;
  27.  
  28. /***************************  INTERNAL VARIABLES  ***************************/
  29.  
  30. static ptr            dosmemory;
  31. static ptr            oldint21;
  32. static handlearrayptr oldhandletable;
  33. static byte           oldnumhandles;
  34. static handlearray    internaltable;
  35.  
  36. static bool initialized = False;
  37.  
  38. /*****************************  IMPLEMENTATION  *****************************/
  39.  
  40. void extendhandles(void) {
  41.     byteptr p;
  42.  
  43.     if (_osmajor == 2) {
  44.         cwrite(LSC_Unable2Extend);                                     /* SN 3.5 */
  45.       cwrite("\n\r");                                                /* SN 3.5 */
  46.         getch();
  47.     }
  48.     else {
  49.         dosmemory = (ptr)internaltable;
  50.         if (dosmemory != NULL) {
  51.             memset(dosmemory,0xFF,sizeof(handlearray));
  52.             p = MK_FP(_psp,0x0032);
  53.             oldnumhandles = *p;
  54.             FP_OFF(p) = 0x0034;
  55.             oldhandletable = *((handlearrayptr *) p);
  56.             FP_OFF(p) = 0x0032;
  57.             *p = sizeof(handlearray);
  58.             FP_OFF(p) = 0x0034;
  59.             *((ptr *) p) = dosmemory;
  60.             memmove(dosmemory,oldhandletable,oldnumhandles);
  61.         }
  62.     }
  63. }
  64.  
  65. /**********************  UNIT INITIALIZATION/EXIT CODE  *********************/
  66.  
  67. void unextendhandles(void) {
  68.     byteptr p;
  69.  
  70.     if (dosmemory != NULL) {
  71.         p = MK_FP(_psp,0x0032);
  72.         *p = oldnumhandles;
  73.         FP_OFF(p) = 0x0034;
  74.         *((ptr *) p) = oldhandletable;
  75.         memmove(oldhandletable,dosmemory,oldnumhandles);
  76.       dosmemory = NULL;
  77.     }
  78. }
  79.  
  80. void extfhc_init(void)
  81. {
  82.     if (!initialized) {
  83.         initialized = True;
  84.         dosmemory = NULL;
  85.         atexit(unextendhandles);
  86.         extendhandles();
  87.     }
  88. }
  89.  
  90. /*****************************  END OF EXTFHC.C  ****************************/
  91.